package com.example.person.config;


import cn.hutool.crypto.digest.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder() {
        this(-1);
    }
    public DefaultPasswordEncoder(int strength) {
    }
    //进行MD5加密
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.create().digestHex(charSequence.toString());
    }
    //进行密码比对
    @Override
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        //测试时如果前端增加了 md5加密 此处要做  如果前端没有做  则这里也不做
        //return encodedPassword.equals(MD5.create().digestHex(charSequence.toString()));
        return encodedPassword.equals(charSequence);
    }
}
